Homework 3 Description

Each map will include (3 maps):

. A Basemap .1) One map with a layer of points o Students may use either circles or markers .2) One map with a layer of lines .3) One map with a layer of polygons Layers . One of the maps must contain a variable which changes of the color of the elements or the marker with an accompanying legend . One map must contain a functioning layersControl()

Get Spatial Data from online

#, 
shape.data.load <- readOGR("./Pittsburgh_Parks", layer = "Pittsburgh_Parks")
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\atirv\Documents\GitHub\Homework_3_Tobie_Irvine\Pittsburgh_Parks", layer: "Pittsburgh_Parks"
## with 214 features
## It has 21 fields
## Integer64 fields read as strings:  objectid_1 objectid
#I have no idea what third argument does
# Last argument (GDAL_integer64_policy = TRUE) results in error: INTEGER() can only #be applied to a 'integer', not a 'double'

Using data from table and merging with spatial data

# Read in CSV File
practical.data <- read.csv("Pittsburgh_Parks_1.csv") 


#pick only rows that match practical datas foreign key values: objectid or #globalid
shape.data.2 <- shape.data.load[shape.data.load$GlobalID_2 %in% practical.data$GlobalID_2,]

#merge practical.data and shape.data.2 to get file used to create base map and 
# assign to data element of shape.data.2; MAKE SURE SORT IS FALSE

shape.data.2@data <- merge(shape.data.2@data, practical.data, sort = FALSE, by.x = "GlobalID_2", by.y = "GlobalID_2")

A Basemap with polygons and the ability to pick different layers

#Pick color palette
pal <- colorFactor(
  palette = "Purples",
  levels =shape.data.2$final_cat.y)
## Warning in colorFactor(palette = "Purples", levels = shape.data.
## 2$final_cat.y): Duplicate levels detected
#Create map with legend
leaflet(shape.data.2) %>% addProviderTiles("OpenStreetMap.BlackAndWhite", options = providerTileOptions(noWrap = TRUE)) %>%
addPolygons(stroke = FALSE, color = ~pal(final_cat.y)) %>%
   addLegend(position = "bottomright", pal = pal, values = shape.data.2$final_cat.y , title = "Parks in Pittsburgh")

A basemap with a layer of railroad lines of PA with layer control.

#get data for railroad lines from GEOjson file
pa.rails <- readOGR("PaRailLines2018_07.geojson")
## OGR data source with driver: GeoJSON 
## Source: "C:\Users\atirv\Documents\GitHub\Homework_3_Tobie_Irvine\PaRailLines2018_07.geojson", layer: "PaRailLines2018_07"
## with 893 features
## It has 34 fields
#Create map
leaflet(data = pa.rails) %>%
  #addProviderTiles("OpenStreetMap.Mapnik") %>% 
  addProviderTiles("OpenMapSurfer.Roads", options = providerTileOptions(noWrap = TRUE), group = "Default") %>%
  addProviderTiles("Esri.DeLorme", options = providerTileOptions(noWrap = TRUE), group = "Topographical") %>%
  addProviderTiles(providers$Esri.WorldImagery, options = providerTileOptions(noWrap = TRUE), group = "World") %>%
  # Layers Control
    addLayersControl(
      baseGroups = c("Default", "Topographical", "World"),
      options = layersControlOptions(collapsed = FALSE)
    )  %>% addPolylines(color = "#63CBD4", popup = ~LINENAME)

## A basemap with points, based on London street crime

#Import data for crimes in London
data.crime <- read.csv("2018-07-city-of-london-street.csv")

#Create map with points representing crime in London. 
leaflet(data = data.crime) %>%
  addProviderTiles("OpenStreetMap.HOT") %>%
  addCircleMarkers(lng = ~Longitude, lat = ~Latitude, radius = 1.5)
## Warning in validateCoords(lng, lat, funcName): Data contains 81 rows with
## either missing or invalid lat/lon values and will be ignored